import os
import time
import pyautogui
import datetime
import socket
import requests

image_dir = "./datas/images"

while True:
	curr_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
	image_file = f"{image_dir}/image_{curr_time}.png"
	print(socket.gethostname(), "save image:", image_file)
	pyautogui.screenshot(image_file)

	# 发送给服务器
	url = "http://192.168.0.109:8888/upload_images"
	params = {"hostname": socket.gethostname()}
	files = {'file': open(image_file, "rb")}
	requests.post(url, files=files, params=params )
	os.remove(image_file)

	time.sleep(3)
